package com.manage.platform.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.manage.platform.service.impl.FileServiceImpl;
import com.manage.platform.utils.R;
import com.manage.platform.service.OssFileService;
import com.manage.platform.vo.FileUploadVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author lk
 * 文件管理
 */
@AllArgsConstructor
@RestController
@RequestMapping("/test")
@Tag(name = "系统设置-文件管理")
public class FileController {

    private final OssFileService ossFileService;
    private final FileServiceImpl fileServiceImpl;

    /**
     * 获取OSS上传令牌
     */
    @GetMapping("/getOssFileToken")
    @Operation(summary = "获取OSS上传令牌")
    @ApiOperationSupport(order = 2)
    public R getOssFileToken() {
        return ossFileService.getOssFileToken();
    }
    /**
     * 上传文件(oss)
     */
    @PostMapping("/ossUploadFile")
    @Operation(summary = "上传文件(oss)")
    @ApiOperationSupport(order = 3)
    public R<String> ossUploadFile(@RequestPart("file") MultipartFile file) {
        return R.ok(ossFileService.ossUploadFile(file));
    }
    /**
     * 批量上传文件(oss)
     */
    @PostMapping("/ossUploadFileList")
    @Operation(summary = "批量上传文件(oss)")
    @ApiOperationSupport(order = 4)
    public R<List<String>> ossUploadFileList(@RequestPart("files") MultipartFile[] file) {
        return R.ok(ossFileService.ossUploadFileList(file));
    }

    @PostMapping("/uploadFile")
    @Operation(summary = "上传文件(服务器)")
    public R<FileUploadVo> uploadFile(@RequestPart("file") MultipartFile file) {
        return R.ok(fileServiceImpl.uploadFile(file));
    }

}
